package com.bdzl.pub.string;

import java.util.Random;

public class TokenUtils {
    
    private final static String key = "xun!@#_$%^qaz*()";

    
    public static String getKey(){
        return key;
    }

    /**
     *
     * @param length
     * @return
     */
    public static String generateToken(int length) {
        String data="0123456789qwertyuiopasdfghjklzxcvbnm";
        return generateToken(data, length);
    }

    public static String generateToken(String data, int length) {
        Random rm = new Random();
        StringBuilder sb = new StringBuilder();
        int i = 0;
        for (int m=0; m<length; m++) {
            i = rm.nextInt(length);
            sb.append(data.charAt(i));
        }
        return sb.toString();
    }
}